namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmPBCTDataAccess
    {
        private WSDmPBCTDataAccess.WSDmPBCTDataAccess wDataAcess = new WSDmPBCTDataAccess.WSDmPBCTDataAccess();
        private SmartSoft.DAL.DmPBCTDataAccess oDataAcess = new SmartSoft.DAL.DmPBCTDataAccess();

        public DmPBCTDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public void CreateInvoice(string ps_Subsidiary, object pd_Ngay_Ct, object ps_Dien_Giai, object ps_Desc_EN, object ps_Ma_Tte, object ps_UserName, object pi_Posted, object pb_Locked, DataTable poDetail)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.CreateInvoice(ps_Subsidiary, pd_Ngay_Ct, ps_Dien_Giai, ps_Desc_EN, ps_Ma_Tte, ps_UserName, pi_Posted, pb_Locked, poDetail);
            }
            else
            {
                oDataAcess.CreateInvoice(ps_Subsidiary, pd_Ngay_Ct, ps_Dien_Giai, ps_Desc_EN, ps_Ma_Tte, ps_UserName, pi_Posted, pb_Locked, poDetail);
            }
        }

        //public bool DeleteDetailRowHS(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.DeleteDetailRowHS(po_Connection, po_Transaction, po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
        //    }
        //    else
        //    {
        //        return oDataAcess.DeleteDetailRowHS(po_Connection, po_Transaction, po_KeyCode);
        //    }
        //}

        //public bool DeleteRowPB(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.DeleteRowPB(po_Connection, po_Transaction, po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
        //    }
        //    else
        //    {
        //        return oDataAcess.DeleteRowPB(po_Connection, po_Transaction, po_KeyCode);
        //    }
        //}

        public DataSet GetDataSet(string ps_Subsidiary, object ps_Loai_PB)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet(ps_Subsidiary, ps_Loai_PB);
            }
            else
            {
                return oDataAcess.GetDataSet(ps_Subsidiary, ps_Loai_PB);
            }
        }

        public DataTable GetDetailTableHS(object ps_KeyCode)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDetailTableHS(ps_KeyCode);
            }
            else
            {
                return oDataAcess.GetDetailTableHS(ps_KeyCode);
            }
        }

        public DataTable GetTablePB(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_KeyCode, ref object pi_TTien0, ref object pi_TTien1)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetTablePB(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_KeyCode, ref pi_TTien0, ref pi_TTien1);
            }
            else
            {
                return oDataAcess.GetTablePB(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_KeyCode, ref pi_TTien0, ref pi_TTien1);
            }
        }

        public DataTable PhanBo_GTCT(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_SPBID, ref object pi_TTien0, ref object pi_TTien1)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_GTCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ref pi_TTien0, ref pi_TTien1);
            }
            else
            {
                return oDataAcess.PhanBo_GTCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ref pi_TTien0, ref pi_TTien1);
            }
        }

        public int PhanBo_HSCT(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_SPBID, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_HSCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_HSCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
        }

        public int PhanBo_TLCT(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_SPBID, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_TLCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_TLCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
        }

        public int PhanBo_TTCT(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_SPBID, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_TTCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_TTCT(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_SPBID, ps_UserName);
            }
        }

        //public int SaveMasterRowHS(SqlConnection po_Connection, SqlTransaction po_Transaction, bool pb_NewChecked, DataRow row)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.SaveMasterRowHS(po_Connection, po_Transaction, pb_NewChecked, row);
        //    }
        //    else
        //    {
        //        return oDataAcess.SaveMasterRowHS(po_Connection, po_Transaction, pb_NewChecked, row);
        //    }
        //}

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }

        public bool SaveRowHS(bool pb_NewChecked, DataRow po_MasterDataRow, DataTable po_DetailDataTable)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRowHS(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(po_MasterDataRow), po_DetailDataTable);
            }
            else
            {
                return oDataAcess.SaveRowHS(pb_NewChecked, po_MasterDataRow, po_DetailDataTable);
            }
        }

        //public int SaveRowPB(SqlConnection po_Connection, SqlTransaction po_Transaction, string ps_Subsidiary, object po_MasterKey, object pd_Ngay_Ct1, object pd_Ngay_Ct2, DataRow poRow)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.SaveRowPB(po_Connection, po_Transaction, ps_Subsidiary, po_MasterKey, pd_Ngay_Ct1, pd_Ngay_Ct2, poRow);
        //    }
        //    else
        //    {
        //        return oDataAcess.SaveRowPB(po_Connection, po_Transaction, ps_Subsidiary, po_MasterKey, pd_Ngay_Ct1, pd_Ngay_Ct2, poRow);
        //    }
        //}

        public bool SaveTablePB(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object po_MasterKey, DataTable po_DetailTable)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveTablePB(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, po_MasterKey, po_DetailTable);
            }
            else
            {
                return oDataAcess.SaveTablePB(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, po_MasterKey, po_DetailTable);
            }
        }
    }
}

